
import requests
def getmail(mail):

    url = "http://mail.xixi1688.com/api/mail/get"
    data = {'receiver': mail, 'token': '9aa9cff4493ad2b5b47da1891979bac0a734aebe'}
    response = requests.get(url=url, params=data)

    if response.status_code == 200:
        print(response.json())

def create(mail):


    url = "http://mail.xixi1688.com/api/user/insert"
    data = {'username': mail, 'token': '9aa9cff4493ad2b5b47da1891979bac0a734aebe',
            'password': '123123'}
    # resp = requests.post(url=url, data=data)
    response = requests.post(url=url, data=data)

    if response.status_code == 200:
        print(response.json())


import poplib
import ssl
import socket


def login_to_pop(email, password, email_service, port=995):
    try:
        # 设置超时时间
        socket.setdefaulttimeout(60)

        # 创建SSL上下文
        # context = ssl.create_default_context()
        # context.check_hostname = False
        # context.verify_mode = ssl.CERT_NONE

        # 连接服务器
        mail = poplib.POP3(email_service, 995)

        # 登录
        mail.user(email)
        mail.pass_(password)

        print("登录成功")
        return mail

    except poplib.error_proto as e:
        print(f"POP3协议错误: {str(e)}")
    except ssl.SSLError as e:
        print(f"SSL错误: {str(e)}")
    except socket.timeout as e:
        print(f"连接超时: {str(e)}")
    except Exception as e:
        print(f"发生错误: {str(e)}")
    return None


if __name__ == '__main__':
    email = "jonathanhanson1934@psychoeducatmail.com"
    password = "jbdyiumtX5511"
    email_service = "imap.firstmail.ltd"

    mail = login_to_pop(email, password, email_service)

    if mail:
        # 如果需要，可以在这里进行其他操作
        mail.quit()
# if __name__ == '__main__':
#     mail = "jerryboren001@xixi1688.com"
#     # create(mail)
#     getmail(mail)
#
#     # http://mail.xixi1688.com/api/mail/get?receiver=aad11212s1a@xixi1688.com&token=9aa9cff4493ad2b5b47da1891979bac0a734aebe
#
